<script setup lang="ts">
import { inject, ref, Ref } from 'vue';

const props = defineProps({
    toggleMenuButtonVisible:{
        type:Boolean,
        defaults:false
    },
    isfixed:{
        type:Boolean,
        defaults:false
    },
})

const menuVisible = inject<Ref<boolean>>('menuVisible') as Ref<boolean>
const toggleMenu = () => {
    menuVisible.value = !menuVisible.value
}

</script>
<template>
    <div class="topnav" :class="{fixed :isfixed}">
        <router-link to="/" class="logo">
            <svg class="icon">
                <use xlink:href="#icon-wind"></use>
            </svg>
        </router-link>
        <ul class="menu">
            <li>
                <router-link to="/doc">文档</router-link>
            </li>
        </ul>
        <svg class="toggleAside" @click="toggleMenu" v-if="toggleMenuButtonVisible">
            <use xlink:href="#icon-switch"></use>
        </svg>
    </div>
</template>

<style scoped lang="scss">
$color:#42b7af;

.topnav {
    color: $color;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    display: flex;
    padding: 16px;
    z-index: 10;
    justify-content: center;
    align-items: center;

    >.logo {
        max-width: 6em;
        margin-right: auto;
        > svg {
            width: 26px;
            height: 26px;
        }
    }

    >.menu {
        display: flex;
        white-space: nowrap;
        flex-wrap: nowrap; //不换行

        >li {
            margin: 0 1em;
        }
    }

    >.toggleAside {
        display: none;
        width: 24px;
        height: 24px;
        position: absolute;
        left: 16px;
        top: 50%;
        transform: translateY(-50%);
    }

    @media (max-width:550px) {
        >.menu {
            display: none;
        }

        >.logo {
            margin: 0 auto;
        }

        >.toggleAside {
            display: inline-block;
        }
    }
}

.fixed{
    position: fixed;
}
</style>